# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <stdbool.h>
# include "tuple.h"

/** Estructura de la Tupla */
struct sTuple
{
    /** Data: Capacidad de la arista */
    Data t_data;
    /** Key: Nodo de una arista */
    Key t_key;
};

/** Constructor de la Tupla*/
Tuple tuple_fromKeyData (Key k, Data d){
    Tuple t = NULL;
    
    t = (Tuple) malloc (sizeof (struct sTuple));
    if (t != NULL){
        t->t_data = d;
        t->t_key = k;
    }
    
    return t;
}

/** Devuelve la primer componente */
Key tuple_fst (Tuple t){
    Key k;
    k = t->t_key;
    return k;
}

/** Devuelve la segunda componente */
Data tuple_snd (Tuple t){
    Data d;
    d = t->t_data;
    return d;
}

/** Devuelve un copia */
Tuple tuple_clone (Tuple t){
    Tuple t_clone;
    Key k;
    Data d;
    
    k = tuple_fst (t);
    d = tuple_snd (t);
    t_clone = tuple_fromKeyData (k,d);
  
    return t_clone;
}

/** Destructor. Destruye la tupla con su Key y Data */
Tuple tuple_destroy(Tuple t){
    free (t);
    return t;
}

/** Compara dos tuplas */
bool tuple_compare (Tuple t1, Tuple t2){
    bool b = false;
    
    if ((t1->t_key == t2->t_key) && (t1->t_data == t2->t_data)){
        b = true;
    }
    
    return b;
}


